package com.xczl.book.action.admin;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shishuo.cms.entity.vo.JsonVo;
import com.xczl.book.entity.BookCate;
import com.xczl.book.service.BookCateService;


@Controller("bookAdminBookCateAction")
@RequestMapping("book/admin/bookcate")
public class BookCateAction {

	@Autowired
	private BookCateService bookCateService;
	
	@RequestMapping("index.htm")
	public String index(ModelMap model) {
		List<BookCate> list = bookCateService.findAll();
		model.addAttribute("list", list);
		return "book/admin/bookcate/index";
	}
	
	@RequestMapping("addPage.htm")
	public String addPage(BookCate bookCate) {
		return "book/admin/bookcate/add";
	}

	@ResponseBody
	@RequestMapping("add.json")
	public JsonVo<String> add(BookCate bookCate) {
		bookCateService.add(bookCate);
		JsonVo<String> json = new JsonVo<String>();// 返回给页面的对象
		json.check();
		return json;
	}
	
	@RequestMapping("editPage.htm")
	public String editPage(int id,ModelMap modelMap) {
		BookCate bookCate=bookCateService.findById(id);
		modelMap.addAttribute("bookCate", bookCate);
		return "book/admin/bookcate/edit";
	}
	
	@ResponseBody
	@RequestMapping("edit.htm")
	public JsonVo<String> edit(BookCate bookCate) {
		bookCateService.update(bookCate);
		JsonVo<String> json = new JsonVo<String>();// 返回给页面的对象
		json.check();
		return json;
	}
}
